package service

import (
	"context"
	"slapp3/backend/application/controller"
	"slapp3/backend/application/domain"
	"slapp3/backend/config"
)

type ConnectService struct {
	ctx            context.Context
	config         *config.Config
	connController *controller.ConnectController
}

// NewConnectService creates a new ConnectService instance
func NewConnectService(ctx context.Context, cfg *config.Config, connController *controller.ConnectController) *ConnectService {
	return &ConnectService{
		ctx:            context.Background(),
		config:         cfg,
		connController: connController,
	}
}

func (s *ConnectService) CreateConnection(profile domain.Profile) error {
	if err := s.connController.CreateConnection(profile); err != nil {
		return err
	}
	return nil
}

func (s *ConnectService) GetConnection(id uint) (domain.Profile, error) {
	profile, err := s.connController.GetConnection(id)
	if err != nil {
		return domain.Profile{}, err
	}
	return profile, nil
}

func (s *ConnectService) UpdateConnection(profile domain.Profile) error {
	if err := s.connController.UpdateConnection(profile); err != nil {
		return err
	}
	return nil
}

func (s *ConnectService) DeleteConnection(id uint) error {
	if err := s.connController.DeleteConnection(id); err != nil {
		return err
	}
	return nil
}

func (s *ConnectService) ListConnections(page, pageSize int) ([]domain.Profile, int64, error) {
	profiles, total, err := s.connController.ListConnections(page, pageSize)
	if err != nil {
		return nil, 0, err
	}
	return profiles, total, nil
}

func (s *ConnectService) Connect(id uint) error {
	if err := s.connController.Connect(id); err != nil {
		return err
	}
	return nil
}

func (s *ConnectService) Disconnect() error {
	if err := s.connController.Disconnect(); err != nil {
		return err
	}
	return nil
}

func (s *ConnectService) IsConnected() bool {

	return false
}

func (s *ConnectService) GetStatus() domain.Stat {
	// Implement logic to retrieve connection statistics
	return domain.Stat{
		BytesSent:     0,
		BytesReceived: 0,
	}
}

func (s *ConnectService) Reconnect() error {

	return nil
}
